package com.ok.common.api

import com.hlyj.http.base.tool.lib_hlyj_base.Constants
import com.hlyj.http.base.tool.lib_hlyj_base.net.CommonInterceptor
import com.hlyj.http.base.tool.lib_hlyj_base.net.MeApi
import com.hlyj.http.base.tool.lib_hlyj_base.net.SSLSocketClient
import com.hlyj.http.base.tool.lib_hlyj_base.net.TimeHttpLoggingInterceptor

import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.net.Proxy
import java.util.concurrent.TimeUnit

object HttpHelper {
    private val BASE_URL = Constants.BASE_URL
    private val okHttpClient: OkHttpClient = OkHttpClient.Builder()
        .proxy(Proxy.NO_PROXY)
        .addInterceptor(TimeHttpLoggingInterceptor())
        .addInterceptor(CommonInterceptor())
        .retryOnConnectionFailure(true) //.sslSocketFactory(SSLSocketClient.getSSLSocketFactory())
        .hostnameVerifier(SSLSocketClient.getHostnameVerifier())
        .connectTimeout(15, TimeUnit.SECONDS)
        .readTimeout(15, TimeUnit.SECONDS)
        .writeTimeout(15, TimeUnit.SECONDS)
        .build()

    private val retrofit: Retrofit = Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(okHttpClient)
        .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .build()

    val api: MeApi = retrofit.create(MeApi::class.java)
}